package main

import (
	"fmt"
	"sync"
	"time"
)

var m = make(map[int]int, 10)

func duoxiecheng() {
	//map 多协程操作
	wg := sync.WaitGroup{}
	wg.Add(2)
	go func(wg *sync.WaitGroup) {
		fmt.Println("m1:", m[1])
		defer wg.Done()
	}(&wg)
	go func(wg *sync.WaitGroup) {
		m[1] = 1
		fmt.Println("m1 set")
		defer wg.Done()
	}(&wg)
	wg.Wait()
}

type stu struct {
	name string
	age  int
}

func main() {

	time.After(time.Second * 2)
	m := map[string]int{"a": 1, "b": 2, "c": 3}
	for k, v := range m {
		go func() {
			fmt.Printf("Key: %s, Value: %d\n", k, v)
		}()
	}

	select {
	case <-time.After(time.Second * 2):
		fmt.Println("timeout")
	}
	//m2 := make(map[string]*stu)
	//stus := []stu{
	//	{
	//		name: "aaa",
	//		age:  2,
	//	},
	//	{
	//		name: "bbb",
	//		age:  3,
	//	},
	//}
	//for _, s := range stus {
	//	m2[s.name] = &s
	//}
	////fmt.Println(stus)
}
